package net.framework.smc.kotlin.demokotlin.controller

import net.framework.smc.kotlin.demokotlin.po.ResultPo
import net.framework.smc.kotlin.demokotlin.po.TripPo
import net.framework.smc.kotlin.demokotlin.service.TripService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.*

/**
 *  @authore zyx
 *  @date 2018/7/6 10:16
 */
@RestController
@RequestMapping("/trip")
class TripController{

    @Autowired
    lateinit var tripService : TripService

    @RequestMapping(value = "/list/{type}", method = arrayOf(RequestMethod.GET))
    fun listTrip(@PathVariable("type") type: Int , @ModelAttribute("userId") userId : String): ResultPo {
        return tripService.listTrip(type, userId)
    }

    @RequestMapping(value = "/{id}", method = arrayOf(RequestMethod.DELETE))
    fun delTrip(@PathVariable("id") id : String) : ResultPo {
        return tripService.delTrip(id)
    }

    @RequestMapping(method = arrayOf(RequestMethod.POST))
    fun addTrip(@RequestBody tripPo : TripPo) : ResultPo {
        return tripService.addTrip(tripPo)
    }

    @RequestMapping(value = "/finished/{id}", method = arrayOf(RequestMethod.PUT))
    fun endTrip(@PathVariable id: String) : ResultPo {
        return tripService.finishedTrip(id)
    }

}